<?php

/**
 * Tanaxia_URI.php
 *
 * The Tanaxia_URI class that will let us get, and manage the URI
 * 
 * Copyright 2009, Marcus Schumann - Tanax
 * Licensed under The MIT License - Modification, Redistribution allowed but must retain the above copyright notice
 * @link 		http://www.opensource.org/licenses/mit-license.php
 *
 * @package 	Tanaxia_URI - TAF
 * @created 	Mars 26th 2009
 * @version 	1.0
 * @link		-
 * 
 * @changelog
 * - 09/03/26	v1.0	Initial release
 */

class Tanaxia_URI
{
	
	/*
	|--------------------------------------------
	| $uri
	|--------------------------------------------
	|
	| An array of all the URI elements in the URL
	|
	*/
	public $uri = array();
	
	/*
	|--------------------------------------------
	| $config
	|--------------------------------------------
	|
	| Contains Tanaxia_Config object
	|
	*/
	private $config;
	
	
	/*
	|--------------------------------------------------------------------------
	| setCore
	|--------------------------------------------------------------------------
	|
	| Set the Tanaxia_Core reference, and run getURI() function
	|
	*/
	public function __construct()
	{
		
		$this->config = Tanaxia_Core::get('config');
		$this->getURI();
		
	}

	/*
	|--------------------------------------------------------------------------
	| getURI
	|--------------------------------------------------------------------------
	|
	| Gets the URI segments and store it in an array
	|
	*/
	private function getURI()
	{
		
		$url = $this->config->base_url . $this->config->index;
		$path = SERVER . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
		
		$uri_string = split($url, $path);
		$this->uri = split('/', $uri_string[1]);
		
	}
	
	/*
	|--------------------------------------------------------------------------
	| segment
	|--------------------------------------------------------------------------
	|
	| Gets the specified segment in the URI - if it exists - otherwise false
	|
	*/
	public function segment($id)
	{
		
		if(isset($this->uri[$id]))
		{
			
			return $this->uri[$id];
			
		}
		
		return false;
		
	}
	
}


// End of Tanaxia_URI.php